package com.example.livingadminmaster.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.livingadminmaster.common.IdWorker;
import com.example.livingadminmaster.mapper.DormitoryTypeMapper;
import com.example.livingadminmaster.pojo.DormitoryType;
import com.example.livingadminmaster.service.DormitoryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DormitoryTypeImpl extends ServiceImpl<DormitoryTypeMapper, DormitoryType> implements DormitoryTypeService {
    IdWorker idWorker = new IdWorker(1, 1);
    @Autowired
    private DormitoryTypeMapper dormitoryTypeMapper;

    @Override
    public List<DormitoryType> getAllDormitoryTypes() {
        List<DormitoryType> dormitoryTypes = dormitoryTypeMapper.selectList(null);
        return dormitoryTypes;
    }

    @Override
    public int addDormitoryType(DormitoryType dormitoryType) {
        long type_id = idWorker.nextId();
        dormitoryType.setTypeId(type_id);
        return dormitoryTypeMapper.insert(dormitoryType);
    }

    @Override
    public int updateDormitoryType(DormitoryType dormitoryType) {
        return dormitoryTypeMapper.updateById(dormitoryType);
    }

    @Override
    public boolean deleteDormitoryType(long type_id) {
        return this.removeById(type_id);
    }
}
